package IO2;

import java.io.*;

/**
 * @description: IO_operation02
 * IO 文件字节流（分段读取）
 * read(byte[])
 * @date: 2019/12/16 21:58
 * @author: Vicuna
 */


public class IO_operation02 {
    public static void main(String[] args) {
        //1.创建源
        File f=new File("E:/Code/Java练习/IO/src/IO2/aaa.txt");
        //2.选择流
        InputStream is=null;
        try {
            is=new FileInputStream(f);
            //3.操作(分段读取）
            byte hc[]=new byte[3];      //缓冲容器
            int len=-1;                 //接收长度；
            while ((len=is.read(hc))!=-1)
            {
                //字符数组-->字符串(解码)
                String s=new String(hc,0,len);
                System.out.println(s);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (null!=is) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
